﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using PCSComUtils.Admin.DS;
using PCSComUtils.Common.DS;
using PCSComUtils.DataAccess;
using PCSComUtils.DataContext;
using PCSComUtils.Framework.TableFrame.DS;
using PCSComUtils.MasterSetup.DS;
using System.Transactions;

namespace PCSComUtils.Common.BO
{
    public class Utilities
    {
        private static readonly object SyncRoot = new object();
        private static Utilities _instance;
        private UtilsDS _utilsDs = new UtilsDS();

        private Utilities()
        {
        }

        public static Utilities Instance
        {
            get
            {
                if (_instance == null)
                {
                    lock (SyncRoot)
                    {
                        if (_instance == null)
                            _instance = new Utilities();
                    }
                }
                return _instance;
            }
        }

        /// <summary>
        /// Cleans the temp table.
        /// </summary>
        public void CleanTempTable()
        {
            _utilsDs.CleanTempTable();
        }

        /// <summary>
        ///     List all supported transaction type in system
        /// </summary>
        /// <returns></returns>
        public List<MST_TranType> GetTransactionTypes()
        {
            using (var db = new PCSDataContext(Utils.Instance.ConnectionString))
            {
                return db.MST_TranTypes.ToList();
            }
        }

        public DateTime GetDBDate()
        {
            using (var db = new PCSDataContext(Utils.Instance.ConnectionString))
            {
                return db.GetServerDate();
            }
        }
        
        public string GetDBVersion()
        {
            string strVersion = string.Empty;
            var dsSysParam = new Sys_ParamDS();
            strVersion = dsSysParam.GetNameValue(SystemParam.DB_VERSION);
            return strVersion;
        }
    }
}